package com.creatapark.monitor.aspect;

import com.creatapark.monitor.annotation.Monitor;
import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Metric
 *
 * @author Bruce01.fan
 * @date 2017/8/15
 */
@Component
@Aspect
public class Metric {

    @Pointcut("execution(public * *(..))")
    public void publicMethods() {

    }

    @Before("publicMethods() && @annotation(monitorAnnotation)")
    public void doBefore(JoinPoint joinPoint, Monitor monitorAnnotation) {
        System.out.println("enter before");
    }

    @AfterReturning(pointcut = "publicMethods() && @annotation(monitorAnnotation) && target(target)",returning = "returned")
    public void doAfter(JoinPoint joinPoint, Monitor monitorAnnotation,Object target,Object returned) {
        System.out.println("enter after , returned obj :" + returned);
    }

}
